home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / jock.zip / TOTSRC11.ZIP / TOTIO3.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-04  |  33KB  |  1,128 lines

  1. {               Copyright 1991 TechnoJock Software, Inc.               }
  2. {                          All Rights Reserved                         }
  3. {                         Restricted by License                        }
  4.  
  5. {                             Build # 1.10                             }
  6.  
  7. Unit totIO3;
  8. {$I TOTFLAGS.INC}
  9.  
  10. {
  11.  Development Notes:
  12.           5/23/91   1.00a    Added reaction to Mouse method 1
  13.           5/29/91   1.00b    Corrected DEL when no chars in list
  14.           7/23/91   1.00c    Corrected DEL when empty lines
  15.           2/06/91   1.00d    Adjusted cursor when list/array assigned
  16.           10/02/92  1.00e    Corrected backspace on empty linked list
  17. }
  18.  
  19. INTERFACE
  20.  
  21. uses DOS, CRT,
  22.      totSYS, totLOOK, totFAST, totSTR, totINPUT, totLINK, totIO1;
  23.  
  24. TYPE
  25.  
  26. pWordwrapIOOBJ = ^WordwrapIOOBJ;
  27. WordwrapIOOBJ = object(MultiLineIOOBJ)
  28.    vTopLine: integer;         {number of first line in window}
  29.    vTotLines: integer;        {total number of lines}
  30.    vListAssigned: boolean;    {is data assigned}
  31.    vScrollBarOn: boolean;     {is the vertical scrollbar required}
  32.    vBoxBorder: boolean;       {is the data enclosed in a box}
  33.    vCursorX: byte;            {position of cursor in Str}
  34.    vCursorY: byte;            {line no. of cursor - from top}
  35.    vMaxLines: integer;        {limit on total number of lines}
  36.    vLineStr: string;          {copy of line being edited}
  37.    vInsert: boolean;          {is field initially in insert mode}
  38.    vWidth: byte;              {maximum width of an input string}
  39.    vEndKey: word;             {key to jump to next field}
  40.    vAllowEdit: boolean;       {can user change the text}
  41.    {methods ...}
  42.    constructor Init(X1,Y1,width,lines:byte;Title:string);
  43.    procedure   WriteLine(OffSet:integer;Status:tStatus);
  44.    procedure   SetEndKey(K:word);
  45.    procedure   SetAllowEdit(On:boolean);
  46.    procedure   DisplayAllLines(Status:tStatus);
  47.    procedure   RefreshScrollBar(Status:tStatus);
  48.    procedure   MoveCursor;
  49.    procedure   CursorJump(Line:integer);
  50.    procedure   CursorUp;
  51.    procedure   CursorDown;
  52.    procedure   CursorLeft;
  53.    procedure   CursorRight;
  54.    procedure   CursorPgUp;
  55.    procedure   CursorPgDn;
  56.    procedure   CursorHome;
  57.    procedure   CursorEnd;
  58.    procedure   CursorTop;
  59.    procedure   CursorBottom;
  60.    procedure   DeleteChar;
  61.    procedure   Backspace;
  62.    procedure   ProcessEnter;
  63.    function    GetNextLinesLeadingSpaces(var StrOne,StrTwo: string;var LastLine: boolean): byte;
  64.    procedure   GetNextLinesFullWords(var StrOne,StrTwo: string;var LastLine: boolean;Line:integer);
  65.    procedure   PushWordsToNextLine(var StrOne,StrTwo: string;var LastLine: boolean;Line:integer);
  66.    procedure   WrapFrom(Line: integer);
  67.    procedure   AdjustMouseKey(var InKey: word;X,Y:byte);
  68.    procedure   MouseChoose(X,Y:byte);
  69.    procedure   ProcessChar(Ch:char);
  70.    procedure   SetIns(InsOn:boolean);
  71.    procedure   WrapFull;                                    VIRTUAL;
  72.    function    Select(K:word; X,Y:byte):tAction;            VIRTUAL;
  73.    function    ProcessKey(InKey:word;X,Y:byte):tAction;     VIRTUAL;
  74.    procedure   Display(Status:tStatus);                     VIRTUAL;
  75.    function    Suspend:boolean;                             VIRTUAL;
  76.    function    GetString(Line:integer): string;             VIRTUAL;
  77.    procedure   SetString(Line:integer;Str: string);         VIRTUAL;
  78.    procedure   DeleteLine(Line:integer);                    VIRTUAL;
  79.    procedure   InsertLine(Line:integer);                    VIRTUAL;
  80.    procedure   InsertAction(InsOn:boolean);                 VIRTUAL;
  81.    destructor  Done;                                        VIRTUAL;
  82. end;
  83.  
  84. pWWArrayIOOBJ = ^WWArrayIOOBJ;
  85. WWArrayIOOBJ = object (WordwrapIOOBJ)
  86.    vArrayPtr: pointer;
  87.    vStrLength: byte;
  88.    {methods ...}
  89.    constructor Init(X1,Y1,width,lines:byte;Title:string);
  90.    procedure   AssignList(var StrArray; Total:Longint; StrLength:byte);
  91.    function    GetString(Line:integer): string;             VIRTUAL;
  92.    procedure   SetString(Line:integer;Str: string);         VIRTUAL;
  93.    procedure   DeleteLine(Line:integer);                    VIRTUAL;
  94.    procedure   InsertLine(Line:integer);                    VIRTUAL;
  95.    destructor  Done;                                        VIRTUAL;
  96. end; {WWArrayIOOBJ}
  97.  
  98. pWWLinkIOOBJ = ^WWLinkIOOBJ;
  99. WWLinkIOOBJ = object (WordwrapIOOBJ)
  100.    vLinkList: ^StrDLLOBJ;
  101.    vWrapping: boolean;
  102.    {methods ...}
  103.    constructor Init(X1,Y1,width,lines:byte;Title:string);
  104.    procedure   AssignList(var LinkList: StrDLLOBJ; Max:integer);
  105.    procedure   WrapFull;                                    VIRTUAL;
  106.    function    GetString(Line:integer): string;             VIRTUAL;
  107.    procedure   SetString(Line:integer;Str: string);         VIRTUAL;
  108.    procedure   DeleteLine(Line:integer);                    VIRTUAL;
  109.    procedure   InsertLine(Line:integer);                    VIRTUAL;
  110.    destructor  Done;                                        VIRTUAL;
  111. end; {WWLinkIOOBJ}
  112.  
  113. procedure IO3Init;
  114.  
  115. IMPLEMENTATION
  116. {||||||||||||||||||||||||||||||||||||||||||||}
  117. {                                            }
  118. {     W W F i e l d O B J   M E T H O D S    }
  119. {                                            }
  120. {||||||||||||||||||||||||||||||||||||||||||||}
  121. constructor WordwrapIOOBJ.Init(X1,Y1,width,lines:byte;Title:string);
  122. {}
  123. begin
  124.    MultiLineIOOBJ.Init(X1,Y1,width,lines,Title);
  125.    vTopLine := 1;
  126.    vTotLines := 0;
  127.    vListAssigned := false;
  128.    vScrollBarOn := false;
  129.    vCursorX := 1;
  130.    vCursorY := 1;
  131.    vInsert := IOTOT^.InputIns;
  132.    vEndKey := 324; {F10}
  133.    vAllowEdit := true;
  134. end; {WordwrapIOOBJ.Init}
  135.  
  136. procedure WordwrapIOOBJ.SetEndKey(K:word);
  137. {}
  138. begin
  139.    vEndKey := K;
  140. end; {WordwrapIOOBJ.SetEndKey}
  141.  
  142. procedure WordwrapIOOBJ.SetAllowEdit(On:boolean);
  143. {}
  144. begin
  145.    vAllowEdit := On;
  146. end; {WordwrapIOOBJ.SetAllowEdit}
  147.  
  148. procedure WordwrapIOOBJ.WriteLine(OffSet:integer;Status:tStatus);
  149. {}
  150. var 
  151.   Str : string;
  152.   A: byte;
  153. begin
  154.    if vListAssigned then
  155.    begin
  156.       Str := GetString(pred(vTopLine)+OffSet);
  157.       Case Status of
  158.          HiStatus: A := IOTOT^.FieldCol(2);
  159.          Norm: A := IOTOT^.FieldCol(1);
  160.          else A := IOTOT^.FieldCol(4);
  161.       end; {case}
  162.       Screen.WriteAT(vBorder.X1,vBorder.Y1+pred(Offset),A,
  163.                      padleft(Str,vBorder.X2-vBorder.X1,' '));
  164.    end;
  165. end; {WordwrapIOOBJ.WriteLine}
  166.  
  167. procedure WordwrapIOOBJ.DisplayAllLines(Status:tStatus);
  168. {}
  169. var I: integer;
  170. begin
  171.    for I := 1 to vRows do
  172.        WriteLine(I,Status);
  173.    if vCursorX > length(vLineStr) then
  174.       CursorEnd
  175.    else
  176.       MoveCursor;
  177. end; {WordwrapIOOBJ.DisplayAllLines}
  178.  
  179. function WordwrapIOOBJ.Select(K:word; X,Y:byte): tAction;
  180. {}
  181. begin
  182.    vScrollBarOn := (vTotLines > vRows);
  183.    Display(HiStatus);
  184.    WriteMessage;
  185.    MoveCursor;
  186.    Select := none;
  187. end; {WordwrapIOOBJ.Select}
  188.  
  189. procedure WordwrapIOOBJ.MoveCursor;
  190. {}
  191. begin
  192.    Screen.GotoXY(pred(vBorder.X1+vCursorX),pred(vBorder.Y1+vCursorY));
  193. end; {WordwrapIOOBJ.MoveCursor}
  194.  
  195. procedure WordwrapIOOBJ.CursorJump(Line:integer);
  196. {}
  197. var
  198.   Tot: integer;
  199. begin
  200.    Tot := vBorder.Y2 - succ(vBorder.Y1);
  201.    Line := Line - vBorder.Y1;
  202.       if vTotLines <= vRows then  {all Lines on display}
  203.       begin
  204.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  205.          vCursorY := (Line * vTotLines) div Tot;
  206.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  207.          CursorHome;
  208.          MoveCursor;
  209.       end
  210.       else
  211.       begin
  212.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  213.          vTopLine := (Line * vTotLines) div Tot;
  214.          vCursorY := 1;
  215.          vCursorX := 1;
  216.          MoveCursor;
  217.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  218.          DisplayAllLines(HiStatus);
  219.       end;
  220. end; {WordwrapIOOBJ.Cursor}
  221.  
  222. procedure WordwrapIOOBJ.CursorUp;
  223. {}
  224. begin
  225.    if vCursorY = 1 then
  226.    begin
  227.       if vTopLine > 1 then
  228.       begin
  229.          SetString(vTopLine,vLineStr);
  230.          dec(vTopLine);
  231.          vLineStr := GetString(vTopLine);
  232.          DisplayAllLines(HiStatus);
  233.       end;
  234.    end
  235.    else
  236.    begin
  237.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  238.       dec(vCursorY);
  239.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  240.       if vCursorX > length(vLineStr) then
  241.          CursorEnd
  242.       else
  243.          MoveCursor;
  244.    end;
  245. end; {WordwrapIOOBJ.CursorUp}
  246.  
  247. procedure WordwrapIOOBJ.CursorDown;
  248. {}
  249. begin
  250.    if pred(vTopLine) + vCursorY < vTotLines then
  251.    begin
  252.       if vCursorY < vRows then
  253.       begin
  254.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  255.          inc(vCursorY);
  256.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  257.          if vCursorX > length(vLineStr) then
  258.             CursorEnd
  259.          else
  260.             MoveCursor;
  261.       end
  262.       else
  263.       begin
  264.          SetString(pred(vTopLine)+vCursorY,vLineStr);
  265.          inc(vTopLine);
  266.          vLineStr := GetString(pred(vTopLine)+vCursorY);
  267.          DisplayAllLines(HiStatus);
  268.       end;
  269.    end;
  270. end; {WordwrapIOOBJ.CursorDown}
  271.  
  272. procedure WordwrapIOOBJ.CursorLeft;
  273. {}
  274. begin
  275.    if vCursorX > 1 then
  276.    begin
  277.       dec(vCursorX);
  278.       MoveCursor;
  279.    end
  280.    else if (vTopLine > 1) or (vCursorY > 1) then
  281.    begin
  282.       CursorUp;
  283.       CursorEnd;
  284.    end;
  285. end; {WordwrapIOOBJ.CursorLeft}
  286.  
  287. procedure WordwrapIOOBJ.CursorRight;
  288. {}
  289. begin
  290.    if vCursorX <= length(vLineStr) then
  291.    begin
  292.       inc(vCursorX);
  293.       MoveCursor;
  294.    end
  295.    else
  296.    begin
  297.       if pred(vTopLine) + vCursorY < vTotLines then
  298.       begin
  299.          CursorDown;
  300.          CursorHome;
  301.       end;
  302.    end;
  303. end; {WordwrapIOOBJ.CursorRight}
  304.  
  305. procedure WordwrapIOOBJ.CursorPgUp;
  306. {}
  307. begin
  308.    if vTopLine > 1 then
  309.    begin
  310.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  311.       vTopLine := vTopLine - vRows;
  312.       if vTopLine < 1 then
  313.          vTopLine := 1;
  314.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  315.       DisplayAllLines(HiStatus);
  316.    end
  317.    else if vCursorY <> 1 then
  318.    begin
  319.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  320.       vCursorY := 1;
  321.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  322.       MoveCursor;
  323.    end;
  324. end; {WordwrapIOOBJ.CursorPgUp}
  325.  
  326. procedure WordwrapIOOBJ.CursorPgDn;
  327. {}
  328. begin
  329.    if pred(vTopLine + vRows) < vTotLines then
  330.    begin
  331.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  332.       vTopLine := vTopLine + vRows;
  333.       vCursorY := 1;
  334.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  335.       DisplayAllLines(HiStatus);
  336.    end
  337.    else if vCursorY + pred(vTopLine) < vTotLines then
  338.    begin
  339.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  340.       vCursorY := vRows;
  341.       if vCursorY + pred(vTopLine) > vTotLines then
  342.          vCursorY := vTotLines - pred(vTopLine);
  343.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  344.       if vCursorX > length(vLineStr) then
  345.          CursorEnd
  346.       else
  347.          MoveCursor;
  348.    end;
  349. end; {WordwrapIOOBJ.CursorPgDn}
  350.  
  351. procedure WordwrapIOOBJ.CursorHome;
  352. {}
  353. begin
  354.    vCursorX := 1;
  355.    MoveCursor;
  356. end; {WordwrapIOOBJ.CursorHome}
  357.  
  358. procedure WordwrapIOOBJ.CursorEnd;
  359. {}
  360. begin
  361.    vCursorX := succ(length(vLineStr));
  362.    MoveCursor;
  363. end; {WordwrapIOOBJ.CursorEnd}
  364.  
  365. procedure WordwrapIOOBJ.CursorTop;
  366. {}
  367. begin
  368.    if (vCursorY <> 1) or (vTopLine <> 1) then
  369.    begin
  370.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  371.       vCursorY := 1;
  372.       vTopLine := 1;
  373.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  374.       DisplayAllLines(HiStatus);
  375.    end;
  376.    CursorHome;
  377. end; {WordwrapIOOBJ.CursorTop}
  378.  
  379. procedure WordwrapIOOBJ.CursorBottom;
  380. {}
  381. begin
  382.    if vTopLine + pred(vRows) >= vTotLines then
  383.       CursorPgDn
  384.    else
  385.    begin
  386.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  387.       vTopLine := vTotLines - pred(vRows);
  388.       vCursorY := vRows;
  389.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  390.       DisplayAllLines(HiStatus);
  391.    end;
  392. end; {WordwrapIOOBJ.CursorBottom}
  393.  
  394. procedure WordwrapIOOBJ.InsertAction(InsOn:boolean);
  395. {}
  396. begin
  397.    if InsOn then
  398.       Screen.CursHalf
  399.    else
  400.       Screen.CursOn;
  401. end; {WordwrapIOOBJ.ChangeMode}
  402.  
  403. procedure WordwrapIOOBJ.SetIns(InsOn:boolean);
  404. {}
  405. begin
  406.    vInsert := InsOn;
  407. end; {WordwrapIOOBJ.SetIns}
  408.  
  409. procedure WordwrapIOOBJ.DeleteChar;
  410. {}
  411. var I : integer;
  412. begin
  413.   if not (     (vLineStr = '')  {1.00b}
  414.            and (vCursorY = 1)
  415.            and (vTopLine = 1)
  416.          ) then
  417.   begin
  418.      if vLineStr = '' then
  419.      begin
  420.         DeleteLine(pred(vTopLine)+vCursorY);
  421.         vLineStr := GetString(pred(vTopLine)+vCursorY);
  422.         for I := vCursorY to vRows do
  423.            WriteLine(I,HiStatus);
  424.         if vCursorY <> 1 then
  425.         begin
  426.            CursorLeft;
  427.            WrapFrom(Pred(vTopLine) + vCursorY);
  428.         end;
  429.      end
  430.      else
  431.      begin
  432.         delete(vLineStr,vCursorX,1);
  433.         SetString(pred(vTopLine)+vCursorY,vLineStr);
  434.         WrapFrom(Pred(vTopLine) + pred(vCursorY));
  435.      end;
  436.   end;
  437. end; {WordwrapIOOBJ.DeleteChar}
  438.  
  439. procedure WordwrapIOOBJ.BackSpace;
  440. {}
  441. begin
  442.    if  not (    (vCursorX = 1)
  443.             and (vCursorY = 1)
  444.             and (vTopLine = 1)
  445.            ) then
  446.    begin
  447.       CursorLeft;
  448.       DeleteChar;
  449.    end;
  450. end; {WordwrapIOOBJ.BackSpace}
  451.  
  452. procedure WordwrapIOOBJ.ProcessEnter;
  453. {splits the line at the cursor, and inserts a blank line}
  454. var
  455.   StrOne, CarryOver: string;
  456.   I : Integer;
  457. begin
  458.   if pred(vTopLine) + vCursorY < pred(vMaxLines) then
  459.   begin
  460.      CarryOver := copy(vLineStr,vCursorX,length(vLineStr)-pred(vCursorX));
  461.      delete(vLineStr,vCursorX,succ(length(vLineStr)-vCursorX));
  462.      SetString(pred(vTopLine)+vCursorY,vLineStr);
  463.      InsertLine(vTopLine+vCursorY);
  464.      if succ(vTopLine + vCursorY) > vTotLines then
  465.         InsertLine(succ(vTopLine+vCursorY));
  466.      if vCursorY + 2 > vRows then
  467.      begin
  468.        if vCursorY = vRows then
  469.           inc(vTopLine,2)
  470.        else
  471.           Inc(vTopLine);
  472.        vCursorY := vRows;
  473.        DisplayAllLines(HiStatus);
  474.      end
  475.      else
  476.      begin
  477.         vCursorY := vCursorY+2;
  478.         for I := 1 to vCursorY do
  479.             WriteLine(I,HiStatus);
  480.      end;
  481.      vCursorX := 1;
  482.      MoveCursor;
  483.      vLineStr := GetString(pred(vTopLine)+vCursorY);
  484.      insert(CarryOver,vLineStr,1);
  485.      WrapFrom(Pred(vTopLine) + vCursorY);
  486.   end;
  487. end; {WordwrapIOOBJ.ProcessEnter}
  488.  
  489. function WordwrapIOOBJ.GetNextLinesLeadingSpaces(var StrOne,StrTwo: string;
  490.                                               var LastLine: boolean): byte;
  491. var Counter : byte;
  492. begin
  493.    counter := 0;
  494.    while (StrTwo <> '')
  495.      and (StrTwo[1] = ' ')
  496.      and (length(StrOne) < vWidth) do
  497.    begin
  498.        StrOne := StrOne + ' ';
  499.        Delete(StrTwo,1,1);
  500.        LastLine := false;
  501.        inc(Counter);
  502.    end;
  503.    GetNextLinesLeadingSpaces := counter;
  504. end; {WordwrapIOOBJ.GetNextLinesLeadingSpaces}
  505.  
  506. procedure WordwrapIOOBJ.GetNextLinesFullWords(var StrOne,StrTwo: string;
  507.                                            var LastLine: boolean; Line: integer);
  508. var
  509.   WordSize: byte;
  510.   RoomLeft: integer;
  511.   Finished: boolean;
  512.   BytesMoved: byte;
  513. begin
  514.    Finished := false;
  515.    BytesMoved := 0;
  516.    repeat
  517.       inc(BytesMoved,GetNextLinesLeadingSpaces(StrOne,StrTwo,LastLine));
  518.       RoomLeft := vWidth - length(StrOne);
  519.       if RoomLeft > 0 then
  520.       begin
  521.          WordSize := pos(' ',StrTwo);
  522.          if WordSize = 0 then
  523.             WordSize := length(StrTwo);
  524.          if (WordSize > 0) and (WordSize <= RoomLeft) then
  525.          begin
  526.              StrOne := StrOne + copy(StrTwo,1,WordSize);
  527.              delete(StrTwo,1,WordSize);
  528.              inc(BytesMoved,WordSize);
  529.              if StrTwo = '' then  {shift up the next line}
  530.              begin
  531.                 DeleteLine(succ(Line));
  532.                 StrTwo := GetString(Succ(Line));
  533.              end;
  534.              if StrTwo = '' then
  535.                 LastLine := true
  536.              else
  537.                 LastLine := false;
  538.          end
  539.          else
  540.             Finished := true;
  541.       end
  542.       else
  543.          Finished := true;
  544.    until Finished;
  545.    if (BytesMoved > 0) and (succ(Line) = pred(vTopLine) + vCursorY) then {move cursor}
  546.    begin
  547.       if vCursorX > BytesMoved then
  548.          dec(vCursorX,BytesMoved)
  549.       else
  550.       begin
  551.          CursorUp;
  552.          vCursorX := length(StrOne) - pred(BytesMoved);
  553.       end;
  554.       MoveCursor;
  555.    end;
  556. end; {WordwrapIOOBJ.GetNextLinesFullWords}
  557.  
  558. procedure WordwrapIOOBJ.PushWordsToNextLine(var StrOne,StrTwo: string;
  559.                                          var LastLine: boolean;Line:integer);
  560. {}
  561. var Counter : integer;
  562. begin
  563.    Counter := length(StrOne);
  564.    repeat
  565.       dec(Counter);
  566.    until (Counter = 0) or ((StrOne[Counter] = ' ') and (Counter <= vWidth));
  567.    {check for STRTWO = ''}
  568.    if StrTwo = '' then {insert a new line}
  569.    begin
  570.       InsertLine(succ(Line));
  571.    end;
  572.    if (Counter = 0) and (length(StrOne)>vWidth) then {no spaces so split word}
  573.       Counter := vWidth;
  574.    insert(copy(StrOne,succ(Counter),length(StrOne)-Counter),StrTwo,1);
  575.    delete(StrOne,succ(Counter),length(StrOne)-Counter);
  576.    if length(StrTwo) > vWidth then
  577.       Lastline := false;
  578. end; {WordwrapIOOBJ.PushWordsToNextLine}
  579.  
  580. procedure WordwrapIOOBJ.WrapFrom(Line:integer);
  581. {}
  582. var
  583.   StrOne,StrTwo: string;
  584.   LastLine: boolean;
  585.   I : integer;
  586. begin
  587.    if Line < 1 then
  588.       Line := 1;
  589.    if Line >= vMaxLines then {nowhere to wrap!}
  590.    begin
  591.       if Line = pred(vTopLine) + vCursorY then
  592.       begin
  593.          if length(vLineStr) > vWidth then
  594.             vLineStr := copy(vLineStr,1,vWidth);
  595.          SetString(vCursorY,vLineStr);
  596.          WriteLine(vCursorY,HiStatus);
  597.       end;
  598.    end
  599.    else
  600.    begin
  601.       if Line = pred(vTopLine) + vCursorY then  {active line}
  602.          StrOne := vLineStr
  603.       else
  604.          StrOne := GetString(Line);
  605.       if succ(Line) =pred(vTopLine) + vCursorY then
  606.          StrTwo := vLineStr
  607.       else
  608.          StrTwo := GetString(succ(Line));
  609.       repeat
  610.          LastLine:= true;
  611.          if length(StrOne) > vWidth then   {line must be truncated}
  612.          begin
  613.             PushWordsToNextLine(StrOne,StrTwo,LastLine,Line);
  614.             SetString(Line,StrOne);
  615.             if not LastLine then
  616.             begin
  617.                Inc(Line);
  618.                StrOne := StrTwo;
  619.                if succ(Line) = pred(vTopLine) + vCursorY then
  620.                   StrTwo := vLineStr
  621.                else
  622.                   StrTwo := GetString(succ(Line));
  623.             end
  624.             else
  625.                SetString(succ(Line),StrTwo);
  626.          end
  627.          else                             {line might be expanded}
  628.          begin
  629.             if StrTwo = '' then
  630.             begin
  631.                Lastline := true;
  632.                SetString(Line,StrOne);
  633.             end
  634.             else
  635.             begin
  636.                LastLine := false;
  637.                if StrOne <> '' then
  638.                   GetNextLinesFullWords(StrOne,StrTwo,LastLine,Line);
  639.               (*
  640.                SetString(Line,StrOne);
  641.                SetString(succ(Line),StrTwo);
  642.                if not LastLine then
  643.                begin
  644.                   Inc(Line);
  645.                   StrOne := StrTwo;
  646.                   StrTwo := GetString(succ(Line));
  647.                end;
  648.                *)
  649.                SetString(Line,StrOne);
  650.                if not LastLine then
  651.                begin
  652.                   Inc(Line);
  653.                   StrOne := StrTwo;
  654.                   StrTwo := GetString(succ(Line));
  655.                end
  656.                else
  657.                   SetString(succ(Line),StrTwo);
  658.             end;
  659.          end;
  660.       Until LastLine;
  661.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  662.       if (vCursorY > 1) and (Line >= vTopLine) then
  663.          WriteLine(pred(vCursorY),HiStatus);
  664.       for I := vCursorY to vRows do
  665.          WriteLine(I,HiStatus)
  666.    end;
  667. end; {WordwrapIOOBJ.WrapFrom}
  668.  
  669. procedure WordwrapIOOBJ.WrapFull;
  670. {Call this method to word wrap an object before displaying it. This saves
  671.  you the chore of inititally wordwrapping the default text.}
  672. var
  673.   StrOne,StrTwo: string;
  674.   LastLine: boolean;   {no used but must be passed to other methods}
  675.   Line : integer;
  676. begin
  677.    if vListAssigned then
  678.    begin
  679.       Line := 1;
  680.       LastLine := false;
  681.       StrOne := GetString(1);
  682.       StrTwo := GetString(2);
  683.       repeat
  684.           if length(StrOne) > vWidth then
  685.             PushWordsToNextLine(StrOne,StrTwo,LastLine,Line)
  686.           else
  687.              if StrOne <> '' then
  688.                 GetNextLinesFullWords(StrOne,StrTwo,LastLine,Line);
  689.           SetString(Line,StrOne);
  690.           Inc(Line);
  691.           if Line <= vMaxLines then
  692.           begin
  693.              StrOne := StrTwo;
  694.              StrTwo := GetString(succ(Line));
  695.           end;
  696.       until Line = vMaxLines;
  697.       SetString(Line,copy(StrOne,1,vWidth));
  698.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  699.    end;
  700. end;  {WordwrapIOOBJ.WrapFull}
  701.  
  702. procedure WordwrapIOOBJ.ProcessChar(Ch:char);
  703. {}
  704. var
  705.   NewX : byte;
  706.   Finished : boolean;
  707. begin
  708.    if not ((vCursorX > vWidth) and (vCursorY + pred(vTopLine) = vMaxLines)) then
  709.    if vInsert then
  710.    begin
  711.       Insert(Ch,vLineStr,vCursorX);
  712.       if  (Ch = ' ')
  713.       and (pos(' ',vLineStr) = vCursorX)
  714.       and (vCursorY <> 1) then {just entered first space on line}
  715.       begin
  716.          CursorRight;
  717.          Wrapfrom(pred(vTopLine)+pred(vCursorY));
  718.       end
  719.       else
  720.       begin
  721.          if length(vLineStr) > vWidth then
  722.          begin
  723.             WrapFrom(pred(vTopLine)+vCursorY);
  724.             if vCursorX > length(vLineStr) then
  725.             begin
  726.                NewX := vCursorX - pred(length(vLineStr));
  727.                CursorHome;
  728.                CursorDown;
  729.                vCursorX := NewX;
  730.                MoveCursor;
  731.             end
  732.             else
  733.                CursorRight;
  734.          end
  735.          else
  736.          begin
  737.             Screen.WriteAT(vBorder.X1,vBorder.Y1+pred(vCursorY),
  738.                            IOTOT^.FieldCol(2),
  739.                            padleft(vLineStr,vWidth,' '));
  740.             CursorRight;
  741.          end;
  742.       end;
  743.    end
  744.    else  {overtype mode}
  745.    begin
  746.          if vLineStr = '' then
  747.              vLineStr := Ch
  748.          else if (vCursorX <= length(vLineStr)) then
  749.             vLineStr[vCursorX] := Ch
  750.          else
  751.             vLineStr := vLineStr + Ch;
  752.       if  ((Ch = ' ')
  753.            and (pos(' ',vLineStr) = vCursorX)
  754.            and (vCursorY <> 1))
  755.       or (vCursorX > vWidth) then {just entered first space on line}
  756.       begin
  757.          Wrapfrom(pred(vTopLine)+pred(vCursorY));
  758.          if vCursorX > length(vLineStr) then
  759.          begin
  760.             NewX := vCursorX - pred(length(vLineStr));
  761.             CursorHome;
  762.             CursorDown;
  763.             vCursorX := NewX;
  764.             MoveCursor;
  765.          end
  766.          else
  767.             CursorRight;
  768.       end
  769.       else
  770.       begin
  771.          Screen.WriteAT(vBorder.X1,vBorder.Y1+pred(vCursorY),IOTOT^.FieldCol(2),
  772.                         padleft(vLineStr,vBorder.X2-vBorder.X1,' '));
  773.          CursorRight;
  774.       end;
  775.    end;
  776. end;  {WordwrapIOOBJ.ProcessChar}
  777.  
  778. procedure WordwrapIOOBJ.AdjustMouseKey(var InKey: word;X,Y:byte);
  779. {}
  780. begin
  781.    if (X = vBorder.X2) and (vScrollBarOn) then {probably on scroll bar}
  782.    begin
  783.       if Y = vBorder.Y2 then
  784.          InKey := 611
  785.       else if Y = vBorder.Y1 then
  786.          InKey := 610
  787.       else if (Y > vBorder.Y1) and (Y < vBorder.Y2) then
  788.          Inkey := 614;
  789.    end;
  790. end; {WordwrapIOOBJ.AdjustMouseKey}
  791.  
  792. procedure WordwrapIOOBJ.MouseChoose(X,Y:byte);
  793. {moves cursor to hit location}
  794. begin
  795.    if (X >= vBorder.X1)
  796.    and (X < vBorder.X2 - ord(not vScrollBarOn))
  797.    and (Y >= vBorder.Y1)
  798.    and (Y <= vBorder.Y2) then
  799.    begin
  800.       vCursorX := X - pred(vBorder.X1);
  801.       SetString(pred(vTopLine)+vCursorY,vLineStr);
  802.       vCursorY := Y - pred(vBorder.Y1);
  803.       vLineStr := GetString(pred(vTopLine)+vCursorY);
  804.       if vCursorX > length(vLineStr) then
  805.          CursorEnd;
  806.       MoveCursor;
  807.    end;
  808. end; {WordwrapIOOBJ.MouseChoose}
  809.  
  810. function WordwrapIOOBJ.ProcessKey(InKey:word;X,Y:byte): tAction;
  811. {}
  812. begin
  813.    if InKey = 513 then
  814.       AdjustMousekey(Inkey,X,Y);
  815.    case InKey of
  816.       610,328,584: CursorUp;   {1.00a}
  817.       611,336,592: CursorDown;
  818.       513: MouseChoose(X,Y);
  819.       337: CursorPgDn;
  820.       329: CursorPgUp;
  821.       335: CursorEnd;
  822.       327: CursorHome;
  823.       388: CursorTop;     {^PgUp}
  824.       374: CursorBottom;  {^PgDn}
  825.       333,587: CursorRight;
  826.       331,589
  827.       : CursorLeft;
  828.       614: begin          {vertical scroll bar}
  829.               if Y = succ(vBorder.Y1) then
  830.                  CursorTop
  831.               else if Y = pred(vBorder.Y2) then
  832.                  CursorBottom
  833.               else
  834.                  CursorJump(Y); {vertical scroll bar}
  835.            end;
  836.       else if vAllowEdit then
  837.          case InKey of
  838.             8:       BackSpace;
  839.             339:     DeleteChar;
  840.             338: begin
  841.                     vInsert := not vInsert;
  842.                     if  (vCursorX > 1)
  843.                     and (vCursorX > length(vLineStr))
  844.                     and not vInsert then {cannot be past end in overtype mode}
  845.                        CursorLeft;
  846.                     InsertAction(vInsert);
  847.                  end;
  848.             13: ProcessEnter;
  849.             32..255: ProcessChar(chr(InKey));    {characters}
  850.          end; {sub case}
  851.    end; {case}
  852.    vScrollBarOn := (vTotLines > vRows);
  853.    RefreshScrollBar(HiStatus);
  854.    if InKey = vEndKey then
  855.       Processkey := NextField
  856.    else
  857.       ProcessKey := None;
  858. end; {WordwrapIOOBJ.ProcessKey}
  859.  
  860. procedure WordwrapIOOBJ.RefreshScrollBar(Status:tStatus);
  861. {}
  862. var Col:byte;
  863. begin
  864.    Case Status of
  865.       HiStatus: Col := IOTOT^.FieldCol(2);
  866.       Norm: Col := IOTOT^.FieldCol(1);
  867.       else Col := IOTOT^.FieldCol(4);
  868.    end; {case}
  869.    with vBorder do
  870.    if vScrollBarOn then
  871.       Screen.WriteVScrollBar(X2,Y1,Y2,Col,pred(vTopLine+vCursorY),vTotLines)
  872.    else
  873.       Screen.WriteVert(X2,Y1,Col,replicate(succ(Y2-Y1),' '));
  874. end; {WordwrapIOOBJ.RefreshScrollBar}
  875.  
  876. procedure WordwrapIOOBJ.Display(Status:tStatus);
  877. {}
  878. var I : integer;
  879. begin
  880.    MultiLineIOOBJ.Display(Status);
  881.    for I := 1 to vRows do
  882.       WriteLine(I,Status);
  883.    RefreshScrollBar(Status);
  884. end; {WordwrapIOOBJ.Display}
  885.  
  886. function WordwrapIOOBJ.Suspend:boolean;
  887. {}
  888. begin
  889.    vScrollBarOn := false;
  890.    SetString(pred(vTopLine)+vCursorY,vLineStr);
  891.    Suspend := VisibleIOOBJ.Suspend;
  892. end; {WordwrapIOOBJ.Suspend}
  893.  
  894. function WordwrapIOOBJ.GetString(Line:integer): string;
  895. {abstract}
  896. begin end;
  897.  
  898. procedure WordwrapIOOBJ.SetString(Line:integer;Str: string);
  899. {abstract}
  900. begin end;
  901.  
  902. procedure WordwrapIOOBJ.DeleteLine(Line:integer);
  903. {abstract}
  904. begin end;
  905.  
  906. procedure WordwrapIOOBJ.InsertLine(Line:integer);
  907. {abstract}
  908. begin end;
  909.  
  910. destructor WordwrapIOOBJ.Done;
  911. {}
  912. begin
  913.    MultiLineIOOBJ.Done;
  914. end; {WordwrapIOOBJ.Done}
  915. {||||||||||||||||||||||||||||||||||||||||||||}
  916. {                                            }
  917. {     W W A r r a y O B J   M E T H O D S    }
  918. {                                            }
  919. {||||||||||||||||||||||||||||||||||||||||||||}
  920. constructor WWArrayIOOBJ.Init(X1,Y1,width,lines:byte;Title:string);
  921. {}
  922. begin
  923.    WordwrapIOOBJ.Init(X1,Y1,width,lines,Title);
  924. end; {WWArrayIOOBJ.Init}
  925.  
  926. procedure WWArrayIOOBJ.AssignList(var StrArray; Total:Longint; StrLength:byte);
  927. {}
  928. begin
  929.    vArrayPtr := @StrArray;
  930.    vStrLength := StrLength;
  931.    vWidth := StrLength;
  932.    vMaxLines := Total;
  933.    vTotLines := Total;
  934.    vListAssigned := true;
  935.    vLineStr := GetString(1);
  936.    vCursorX := 1;   {1.00d}
  937.    vCursorY := 1;
  938. end; {WWArrayIOOBJ.AssignList}
  939.  
  940. function WWArrayIOOBJ.GetString(Line:integer): string;
  941. {}
  942. var
  943.   W : word;
  944.   TempStr : String;
  945.   ArrayOffset: word;
  946. begin
  947.    if (Line > 0) and (Line <= vTotLines) then
  948.    begin
  949.       W := pred(Line) * succ(vStrLength);
  950.       ArrayOffset := Ofs(vArrayPtr^) + W;
  951.       Move(Mem[Seg(vArrayPtr^):ArrayOffset],TempStr,1);
  952.       Move(Mem[Seg(vArrayPtr^):succ(ArrayOffset)],TempStr[1],ord(TempStr[0]));
  953.    end
  954.    else
  955.       TempStr := '';
  956.    GetString := TempStr;
  957. end; {WWArrayIOOBJ.GetString}
  958.  
  959. procedure WWArrayIOOBJ.SetString(Line:integer;Str: string);
  960. {}
  961. var
  962.   W : word;
  963.   ArrayOffset: word;
  964. begin
  965.    if (Line > 0) and (Line <= vTotLines) then
  966.    begin
  967.       W := pred(Line) * succ(vStrLength);
  968.       ArrayOffset := Ofs(vArrayPtr^) + W;
  969.       Move(Str[0],Mem[Seg(vArrayPtr^):ArrayOffset],succ(length(Str)));
  970.    end;
  971. end; {WWArrayIOOBJ.SetString}
  972.  
  973. procedure WWArrayIOOBJ.DeleteLine(Line:integer);
  974. {}
  975. var
  976.   Null : char;
  977.   W : word;
  978.   ArrayOffset: word;
  979. begin
  980.    if (Line > 0) and (Line <= vTotLines) then
  981.    begin
  982.       W := pred(Line) * succ(vStrLength);
  983.       ArrayOffset := Ofs(vArrayPtr^) + W;
  984.       Move(Mem[Seg(vArrayPtr^):ArrayOffset+succ(vStrLength)],
  985.            Mem[Seg(vArrayPtr^):ArrayOffset],
  986.            (vTotLines - Line)*succ(vStrlength));
  987.       {empty last line}
  988.       W := pred(vTotLines) * succ(vStrLength);
  989.       ArrayOffset := Ofs(vArrayPtr^) + W;
  990.       Null := char(0);
  991.       Move(Null,Mem[Seg(vArrayPtr^):ArrayOffset],1);
  992.    end;
  993. end; {WWArrayIOOBJ.DeleteLine}
  994.  
  995. procedure WWArrayIOOBJ.InsertLine(Line:integer);
  996. {}
  997. var
  998.   Null : char;
  999.   W : word;
  1000.   ArrayOffset: word;
  1001. begin
  1002.    if (Line > 0) and (Line <= vTotLines) then
  1003.    begin
  1004.       W := pred(Line) * succ(vStrLength);
  1005.       ArrayOffset := Ofs(vArrayPtr^) + W;
  1006.       Move(Mem[Seg(vArrayPtr^):ArrayOffset],
  1007.            Mem[Seg(vArrayPtr^):ArrayOffset+succ(vStrLength)],
  1008.            (vTotLines - Line)*succ(vStrlength));
  1009.       {empty new line}
  1010.       Null := char(0);
  1011.       Move(Null,Mem[Seg(vArrayPtr^):ArrayOffset],1);
  1012.    end;
  1013. end; {WWArrayIOOBJ.InsertLine}
  1014.  
  1015. destructor WWArrayIOOBJ.Done;
  1016. {}
  1017. begin
  1018.    WordwrapIOOBJ.Done;
  1019. end; {WWArrayIOOBJ.Done}
  1020. {||||||||||||||||||||||||||||||||||||||||||}
  1021. {                                          }
  1022. {     W W L i n k O B J   M E T H O D S    }
  1023. {                                          }
  1024. {||||||||||||||||||||||||||||||||||||||||||}
  1025. constructor WWLinkIOOBJ.Init(X1,Y1,width,lines:byte;Title:string);
  1026. {}
  1027. begin
  1028.    WordwrapIOOBJ.Init(X1,Y1,width,lines,Title);
  1029.    vWidth := pred(vBorder.X2 - vBorder.X1);
  1030.    vWrapping := false;
  1031. end; {WWLinkIOOBJ.Init}
  1032.  
  1033. procedure WWLinkIOOBJ.AssignList(var LinkList:StrDLLOBJ; Max:integer);
  1034. {}
  1035. begin
  1036.    vLinkList := @LinkList;
  1037.    vMaxLines := Max;
  1038.    vTotLines := LinkList.TotalNodes;
  1039.    vListAssigned := true;
  1040.    vLineStr := GetString(1);
  1041.    vScrollBarOn := (vTotLines > vRows);
  1042.    vCursorX := 1;   {1.00d}
  1043.    vCursorY := 1;
  1044. end; {WWLinkIOOBJ.AssignList}
  1045.  
  1046. function WWLinkIOOBJ.GetString(Line:integer): string;
  1047. {}
  1048. var
  1049.   TempPtr : DLLNodePtr;
  1050. begin
  1051.    TempPtr := vLinkList^.NodePtr(Line);
  1052.    if TempPtr <> Nil then
  1053.       vLinkList^.ShiftActiveNode(TempPtr,Line);
  1054.    if vWrapping then
  1055.       GetString := vLinkList^.GetStr(TempPtr,1,255)
  1056.    else
  1057.       GetString := vLinkList^.GetStr(TempPtr,1,vWidth)
  1058. end; {WWLinkIOOBJ.GetString}
  1059.  
  1060. procedure WWLinkIOOBJ.SetString(Line:integer;Str: string); {1.00e}
  1061. {}
  1062. var
  1063.   Ecode: integer;
  1064.   NP : DllNodePtr;
  1065. begin
  1066.    NP := vLinkList^.NodePtr(Line);
  1067.    if NP = nil then
  1068.       ECode := vLinkList^.Add(Str)
  1069.    else
  1070.       ECode := vLinkList^.Change(NP,Str);
  1071. end; {WWLinkIOOBJ.SetString}
  1072.  
  1073. procedure WWLinkIOOBJ.DeleteLine(Line:integer);
  1074. {}
  1075. begin
  1076.    vLinkList^.DelNode(vLinkList^.NodePtr(Line));
  1077.    dec(vTotLines);
  1078.    vLinkList^.ShiftActiveNode(vLinkList^.NodePtr(1),1);  {1.00c}
  1079. end; {WWLinkIOOBJ.DeleteLine}
  1080.  
  1081. procedure WWLinkIOOBJ.InsertLine(Line:integer);
  1082. {}
  1083. var
  1084.   Null: string;
  1085.   ECode: integer;
  1086. begin
  1087.    Null := '';
  1088.    Ecode := vLinkList^.InsertBefore(vLinkList^.NodePtr(Line),Null);
  1089.    if Ecode = 3 then {add a new line to end of list}
  1090.       Ecode := vLinkList^.Add(Null);
  1091.    vTotLines := vLinkList^.TotalNodes;
  1092. end; {WWLinkIOOBJ.InsertLine}
  1093.  
  1094. procedure WWLinkIOOBJ.WrapFull;
  1095. {}
  1096. begin
  1097.    vWrapping := true;
  1098.    WordwrapIOOBJ.WrapFull;
  1099.    with vLinkList^ do
  1100.       ShiftActiveNode(EndNodePtr,TotalNodes);
  1101.    vWrapping := false;
  1102.    vTotLines := vLinkList^.TotalNodes;
  1103.    vScrollBarOn := (vTotLines > vRows);
  1104. end; {WWLinkIOOBJ.WrapFull}
  1105.  
  1106. destructor WWLinkIOOBJ.Done;
  1107. {}
  1108. begin
  1109.    WordwrapIOOBJ.Done;
  1110. end; {WWLinkIOOBJ.Done}
  1111. {|||||||||||||||||||||||||||||||||||||||||||||||}
  1112. {                                               }
  1113. {     U N I T   I N I T I A L I Z A T I O N     }
  1114. {                                               }
  1115. {|||||||||||||||||||||||||||||||||||||||||||||||}
  1116. procedure IO3Init;
  1117. {initilizes objects and global variables}
  1118. begin
  1119.  
  1120. end; {IO3Init}
  1121.  
  1122. {end of unit - add initialization routines below}
  1123. {$IFNDEF OVERLAY}
  1124. begin
  1125.    IO3Init;
  1126. {$ENDIF}
  1127. end.
  1128.